﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.Devices;
namespace PrimeFactorization
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            ComputerInfo info = new ComputerInfo();

            string OSVersionFull = info.OSVersion.ToString();
            int OS = Convert.ToInt32(OSVersionFull.Substring(4, 1).ToString());



     if (OS == 2)
       {
           label2.BackColor = Color.SeaGreen;
           ACForm.ChangeBackColorForXP = Color.SeaGreen;
       }
    else  if(OS == 7 || OS == 8);
            
            else
            {
                UnkownOS OSUnknown = new UnkownOS();
                OSUnknown.ShowDialog();
                

            }

            
                
        
        }

       Secondary_AC_Form ACForm = new Secondary_AC_Form();
   
        FactorsOfANumber FactorClass = new FactorsOfANumber();
      

        int counter = 0;
        

        private void Expand_Contract_Click(object sender, EventArgs e)
        {
            counter++;
            if (counter == 1)
            {
                Expand_Contract.Text = "<";
                ACForm.Show();
                Activate();

               

                int dif = MainForm.ActiveForm.Height - MainForm.ActiveForm.ClientRectangle.Height;
           
               
                ACForm.SetDesktopLocation(MainForm.ActiveForm.Location.X + MainForm.ActiveForm.Width - 4, MainForm.ActiveForm.Location.Y + dif-3 );
            }
            else if (counter == 2)
            {
                Expand_Contract.Text = ">";
                counter = 0;
                ACForm.Hide();
                
            }
           
        }
        int errorcounter = 0;
        private void MoveWithACForm(object sender, EventArgs e)
        {
            try
            {

                int dif = MainForm.ActiveForm.Height - MainForm.ActiveForm.ClientRectangle.Height;

                ACForm.SetDesktopLocation(MainForm.ActiveForm.Location.X + MainForm.ActiveForm.Width - 4, MainForm.ActiveForm.Location.Y + dif -3);
            }
            catch { errorcounter++; }
        }
        
        public void ACNumberUpDown_ValueChanged(object sender, EventArgs e)
        {
            
            {
                string[] ReturnedFactors = new string[1000];
                ACForm.ACENTRY.Value = ACNumberUpDown.Value;
                ReturnedFactors = FactorClass.factors_of_number(false,Convert.ToInt32(ACNumberUpDown.Value), null);

                Factors_ListBox.Items.Clear();

                foreach (string Factor in ReturnedFactors)
                {
                    if (Factor != null)
                    {
                        Factors_ListBox.Items.Add(Factor.ToString());
                    }


                }
                if (Factors_ListBox.Items.Count == 1 || ACNumberUpDown.Value == 0 || ACNumberUpDown.Value == 1 || ACNumberUpDown.Value == -1)
                {
                    Prime_NotPrime.Text = "Prime!";
                }
                else
                {
                    Prime_NotPrime.Text = "Factorable!";
                }
            }

        }

        private void PictureLogo_Click(object sender, EventArgs e)
        {
            AboutBox1 About = new AboutBox1();
            About.Show();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
           
            ACForm.ChangeInAC_Event += AcentryChanged;
           
            
        }

        private void AcentryChanged(object sender, Secondary_AC_Form.ChangeInACEntry e)
        {
            ACNumberUpDown.Value = e.NewNumber;

        }

        private void FirstShown(object sender, EventArgs e)
        {
            try
            {

                SendKeys.Send("%");
                WindowState = FormWindowState.Normal;
            }
            catch
            {

                Close();
            }
            
          
        }

       

     
         
    }
}
